package com.hunan.api.catv.action.tvv3;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.service.biz.tvv3.TvV3Biz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author jiang zhuan
 * @version 1.0
 * @description 描述
 * @date 2021/10/14 0014
 * @package com.hunan.api.catv.action.tvv3
 * @company 湖南有线
 */
@RestController
@RequestMapping(Api.tvv3)
public class TvToolAction extends BaseAction {
    @Autowired
    TvV3Biz tvV3Biz;

    @PostMapping("/startMode/change")
    @MemberAuth
    public Result startModeChange(HttpServletRequest request, String user_id) {
        return buildResult(tvV3Biz.chageStartMode(getMemberId(request), user_id));
    }

    @GetMapping("/startMode")
    @MemberAuth
    public Result queryStartMode(HttpServletRequest request) {
        Object o = tvV3Biz.queryStartMode(getMemberId(request));
        if (o instanceof ServiceResult) {
            return buildResult((ServiceResult) o);
        }
        return buildOK(o, "");
    }

    @PostMapping("/child/timeLimit/change")
    @MemberAuth
    public Result changeChildModeTimeLimit(HttpServletRequest request, Integer minute) {
        return buildResult(tvV3Biz.changeChildModeTimeLimit(getMemberId(request), minute));
    }

    @GetMapping("/child/timeLimit")
    @MemberAuth
    public Result queryChildModeTimeLimit(HttpServletRequest request) {
        Object o = tvV3Biz.queryChildModeTimeLimit(getMemberId(request));
        if (o instanceof ServiceResult) {
            return buildResult((ServiceResult) o);
        }
        return buildOK(o, "");
    }

    @MemberAuth
    @GetMapping("/history/{pageNum}/{pageSize}/{type}")
    public Result queryTvHistory(HttpServletRequest request, @PathVariable Integer pageNum, @PathVariable Integer pageSize, @PathVariable Integer type) {
        Object o = tvV3Biz.queryTvHistory(getMemberId(request), pageNum, pageSize, type);
        if (o instanceof ServiceResult) {
            return buildResult((ServiceResult) o);
        }
        return buildOK(tvV3Biz.queryTvHistory(getMemberId(request), pageNum, pageSize, type), "");
    }

}
